<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/1/28
 * Time: 13:08
 */

namespace App\Http\Logics\Admin;


use App\WechatArticle;
use App\Http\Logics\BaseLogic;
class WechatArticleLogic extends BaseLogic
{
    public static function pushArticle($data)
    {
        $wechat_article = new WechatArticle();
        $wechat_article->article_title= $data['article_title'];
        $wechat_article->article_author = $data['article_author'];
        $wechat_article->weixin_name = $data['weixin_name'];
        $wechat_article->weixin_nickname = $data['weixin_nickname'];
        $wechat_article->article_publish_time = $data['article_publish_time'];
        $wechat_article->article_thumbnail = $data['article_thumbnail'];
        $wechat_article->article_brief = $data['article_brief'];
        $wechat_article->article_content = $data['article_content'];
        $wechat_article->is_original = $data['is_original'] === '是' ? 1 : 0;
        $wechat_article->weixin_avatar = $data['weixin_avatar'];
        $wechat_article->weixin_introduce = $data['weixin_introduce'];
        $wechat_article->weixin_qr_code = $data['weixin_qr_code'];
        $wechat_article->article_images = $data['article_images'];
        $wechat_article->idx = $data['idx'];
        if (!$wechat_article->save()){
            return self::response(self::OBJECT_SAVE_FAIL);
        }
        return self::response(self::SUCCESS);
    }

    public static function getWechatArticleList($data)
    {
        $query = WechatArticle::with(['partner'])->orderBy('article_publish_time', 'desc');

        $aritlce = $data['limit'] ? $query->paginate($data['limit']) : $query->get();
        if (empty($aritlce)){
            return self::response(self::CONTENT_IS_EMPTY);
        }
        return self::response(self::SUCCESS, $aritlce);
    }
}